<?php
// +----------------------------------------------------------------------
// | Copyright (c) 2020 All rights reserved.
// +----------------------------------------------------------------------
// | User: Simony <1362229026@qq.com>
// | wechat: Shen86579595
// +----------------------------------------------------------------------

namespace app\common\model\bonus;

use app\common\model\Base;

use think\db;

class Bonus extends Base
{
    protected $name = 'bonus';

    CONST SECOND_GRANT = 0;
    CONST DAY_GRANT = 1;
    CONST WEEK_GRANT = 2;
    CONST MONTH_GRANT = 3;
    public $grant_types = [ //0秒发 、1日发 、2周发、3月发
        0 => '秒发',
        1 => '日发',
        2 => '周发',
        3 => '月发',
    ];

    /**
     * User:Simony
     * Function: 列表
     * @param $condition
     * @param int $page
     * @param string $field
     * @param string $order
     * @return array|\PDOStatement|string|\think\Collection
     * @throws \think\exception\DbException
     * @throws db\exception\DataNotFoundException
     * @throws db\exception\ModelNotFoundException
     */
    public function getBonusList($condition = [], $page = 0, $field = 'b.*,m.nickname', $order = 'b.periods desc')
    {

        $res = $this->alias('b')
            ->join('member m', 'b.member_id=m.id', 'left')
            ->where($condition)
            ->field($field)
            ->order($order);

        if ($page) {
            $res = $res->paginate($page, false, ['query' => request()->param()]);
            $this->page_info = $res;
            $res = $res->toArray();
            return $res['data'];
        } else {
            return $res->select()->toArray();
        }
    }
}
